// ==UserScript== // @name ChatGPT撑开页面宽度 // @namespace https://greasyfork.org/ // @version 1.1.1-1 // @description 将页面宽度展开 // @author OpenAI - ChatGPT // @match https://chat.openai.com/ // @match https://chat.openai.com/c/* // @match https://chat.openai.com/?* // @license AGPL-3.0-or-later // ==/UserScript== (function () { "use strict"; const newMaxWidth = "90rem"; const targetClassName = ".xl\\:max-w-3xl"; const targetClass = "flex flex-col text-sm dark:bg-gray-800"; const desiredMinWidth = 1280; function btnClick() { const toggleButton = document.querySelector("nav"); if (!toggleButton) { setTimeout(function () { btnClick(); }, 1000); return; } toggleButton.insertAdjacentHTML( "beforeend", '
如果页面宽度未展开,请重新点击此树结构导航栏
或者直接点击我
提示内容十秒后自动消失
' ); const btn = document.getElementById("btnClick"); btn.addEventListener("click", function () { run(); }); setTimeout(function () { btn.remove(); }, 10000); toggleButton.addEventListener("click", function () { setTimeout(function () { run(); btnClick(); }, 1000); }); } function checkForm() { var elementForm = document.querySelectorAll("form"); if (!elementForm || elementForm.length === 0) { setTimeout(function () { checkObserver(); }, 1000); return; } elementForm.forEach(function (element) { if (element.className.indexOf("xl:max-w-3xl") > -1) { editStyle(element); } }); } function checkObserver() { var parentElement = document.getElementsByClassName(targetClass)[0]; if (!parentElement) { setTimeout(function () { checkObserver(); }, 1000); return; } parentElement.querySelectorAll(targetClassName).forEach(function (flexDiv) { editStyle(flexDiv); }); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (addedNode) { var flexDivs = addedNode.querySelectorAll(targetClassName); flexDivs.forEach(function (flexDiv) { editStyle(flexDiv); }); }); }); }); var config = { childList: true, subtree: true }; observer.observe(parentElement, config); } function editStyle(el) { el.style.transition = "max-width 1s"; setTimeout(function () { el.style.transition = ""; }, 1000); el.style.maxWidth = newMaxWidth; } function run() { checkForm(); checkObserver(); } window.addEventListener("resize", run); window.onload = function () { if (window.innerWidth < desiredMinWidth) { return; } btnClick(); setTimeout(function () { run(); }, 2000); }; })();